# -*- coding: utf-8 -*-
# @Author   : 白云酱
# Data      :
# Software  :pyChrom
# version   :python 3.10
# @File     :expected_operation.py

from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver.support.wait import WebDriverWait

from libs.base_driver import BaseDriver


class ECOption:
    def __init__(self,driver:BaseDriver):
        self.base = driver

    def title_is(self,title:str) ->bool:
        """判断当前页面的title是都完全等于预期字符串"""
        return WebDriverWait(self.base.driver,10).until(EC.title_is(title),message=f"结果不等于[{title}]")

    def does_exist(self,locator: tuple) -> WebElement:
        """判断元素是否出现,只有一个元素返回元素对象"""
        param = self.base.locator_validation(locator)
        return WebDriverWait(self.base.driver, 10, 0.2).until(
        EC.presence_of_element_located(param),message=f"未找到元素:{locator}")

